const app= getApp()
Page({
  data: {
    isSubmitting: false,
    currentTab: 'basic',
    formData: {
    }
  },


  handleSubmit() {
    let baseURL = `${app.globalData.baseUrl}/api/user/prereserve/`
    let URL = ""
    // 根据 currentTab 获取子组件实例
    const className = `.${this.data.currentTab}`;
    const childComponent = this.selectComponent(className);
    // 根据组件类名 获取子组件实例
    if (!childComponent) {
      wx.showToast({ title: '未找到子组件', icon: 'none' });
      return;
    }
    // 获取子组件数据
    this.data.formData = childComponent.getFormData();
    console.log('待提交的数据:', this.data.formData);

    // 根据当前的className动态拼接相应的URL
    if(className === ".basic") {
      URL = baseURL + "basic-info"
      console.log(URL)
    } else if(className === ".military") {
      URL = baseURL + "military-info"
    } else if(className === ".service") {
      URL = baseURL + "retired-info"
    } else if(className === ".education") {
      URL = baseURL + "study-info"
    }
    console.log(URL)
    

    // 根据获取的数据进行提交操作
    wx.request({
      url: URL,
      method: 'POST',
      data: this.data.formData,
      success(res) {
        // 提交成功后的处理
        wx.showToast({ title: '提交成功' });
      },
      fail(err) {
        // 提交失败后的处理
        wx.showToast({ title: '提交失败', icon: 'none' });
      },
      complete(res) {
        console.log(res)
      }
    });
  },
  // 顶部导航栏切换
  switchTab(e) {
    const tab = e.currentTarget.dataset.tab;
    this.setData({
      currentTab: tab
    });
  },

});